﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

#if UNITY_EDITOR
using UnityEngine;
#endif

namespace USNetFramework.Utils
{
    public class Log
    {
        public static string Module = "[NetSocket]";


        public static void WriteError(string str, params object[] fmt)
        {
            Write("[Error]", str, fmt);
        }


        public static void WriteWarnning(string str, params object[] fmt)
        {
            Write("[Warnning]", str, fmt);
        }


        public static void WriteInfo(string str, params object[] fmt)
        {
            Write("[info]", str, fmt);
        }


        public static void Write(string tag = "", string str = "", params object[] fmt)
        {
#if UNITY_EDITOR
            Debug.LogFormat(Module + tag + " " + str, fmt);
#else
            Console.WriteLine(Module + tag + " " + str, fmt);
#endif
        }


        public static void WriteException(Exception ex)
        {
            Write("*****************************************["
                               + DateTime.Now.ToLongTimeString()
                               + "]*****************************************");
            if (ex != null)
            {
                Write("[Module]" + Module);
                Write("[ErrorType]" + ex.GetType());
                Write("[TargetSite]" + ex.TargetSite);
                Write("[Message]" + ex.Message);
                Write("[Source]" + ex.Source);
                Write("[StackTrace]" + ex.StackTrace);
            }
            else
            {
                Write("Exception is NULL");
            }
        }
    }
}
